// TBGenWnd.cpp : implementation file
//

#include "stdafx.h"
#include "StdArx.h"
#include "TBGenWnd.h"
#include "Resource.h"
#include "WindoTypeDlg.h"
#include "WindoInfoDlg.h"
#include "rxmfcapi.h"

#include "gepnt2d.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


extern CWindoTypeDlg* g_pWindoTypeDlg;

//extern HINSTANCE hResource;
extern void drawWindo();

/////////////////////////////////////////////////////////////////////////////
// CTBGenWnd

CTBGenWnd::CTBGenWnd()
{
}

CTBGenWnd::~CTBGenWnd()
{
}


BEGIN_MESSAGE_MAP(CTBGenWnd, CWnd)
	//{{AFX_MSG_MAP(CTBGenWnd)
	ON_COMMAND(ID_TBTN_WINDDLG, OnShowWindTypeDlg)
	ON_COMMAND(ID_TBTN_DRAW, OnDrawWindo)
	ON_COMMAND(ID_TBTN_INFO, OnWindInfoDlg)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CTBGenWnd message handlers

void CTBGenWnd::OnShowWindTypeDlg() 
{
	if(g_pWindoTypeDlg != NULL && !g_pWindoTypeDlg->IsWindowVisible())
	{
		g_pWindoTypeDlg->ShowWindow(SW_SHOW);
	}
	else if(g_pWindoTypeDlg != NULL)
	{
		g_pWindoTypeDlg->ShowWindow(SW_SHOW);
	}
	else
	{
		CAcModuleResourceOverride resOverride;

		g_pWindoTypeDlg = new CWindoTypeDlg(acedGetAcadFrame());
		g_pWindoTypeDlg->Create(IDD_WINDOTYPE, acedGetAcadFrame());
		g_pWindoTypeDlg->CenterWindow();
		g_pWindoTypeDlg->ShowWindow(SW_SHOW);

		((CButton*) g_pWindoTypeDlg->GetDlgItem(IDC_CHK_VISTB))->SetCheck(1);
		g_pWindoTypeDlg->GetDlgItem(IDC_BTN_HIDEDLG)->EnableWindow(TRUE);

	}
}

void CTBGenWnd::OnDrawWindo()
{
	if(g_pWindoTypeDlg != NULL)
	{
		g_pWindoTypeDlg->UpdateData(TRUE);
		
		// Transfer the values in the dialog
		// back to the global variables

		windInfo.m_dWindHt		= g_pWindoTypeDlg->m_dHeight;
		windInfo.m_dWindWt		= g_pWindoTypeDlg->m_dWidth;
		windInfo.m_nCols		= g_pWindoTypeDlg->m_nCols;
		windInfo.m_nRows		= g_pWindoTypeDlg->m_nRows;
		windInfo.m_nWindType	= g_pWindoTypeDlg->m_nWindType;
		windInfo.m_startPt.x	= g_pWindoTypeDlg->m_dXVal;
		windInfo.m_startPt.y	= g_pWindoTypeDlg->m_dYVal;
	}

	drawWindo();	
}

void CTBGenWnd::OnWindInfoDlg() 
{
	CAcModuleResourceOverride resOverride;

	CWindoInfoDlg dlg;
	dlg.DoModal();
}

void CTBGenWnd::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	
	CWnd::OnClose();
}

void CTBGenWnd::PostNcDestroy() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CWnd::PostNcDestroy();
}
